#!/usr/bin/python
# encoding: utf-8
'''
fbtop.fbtop -- Top like tool for Firebird
'''

import os
import sys
from ui import Ui

from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter

__all__ = []
__version__ = 0.1
__date__ = '2013-05-19'
__updated__ = '2013-05-19'

DEBUG = 0
TESTRUN = 0
PROFILE = 0

server = None

    
class CLIError(Exception):
    pass




def main(argv=None): # IGNORE:C0111
    '''Command line options.'''
    
    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Created by John Ryder on %s.
  
  Licensed under the MIT license
  http://opensource.org/licenses/mit-license.php
  
  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % (program_shortdesc, str(__date__))

   
    # Setup argument parser
    parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
    parser.add_argument("-s", "--server", dest="server", help="server to monitor")
    parser.add_argument("-p", "--password", dest="password", help="SYSDBA password")
    parser.add_argument('-v', '--version', action='version', version=program_version_message)
    
    # Process arguments
    #args = parser.parse_args()
    
    ui = Ui("localhost", "SYSDBA", "masterkey")
    ui.run()

if __name__ == "__main__":
    
    if TESTRUN:
        import doctest
        doctest.testmod()
    if PROFILE:
        import cProfile
        import pstats
        profile_filename = 'fbtop.fbtop_profile.txt'
        cProfile.run('main()', profile_filename)
        statsfile = open("profile_stats.txt", "wb")
        p = pstats.Stats(profile_filename, stream=statsfile)
        stats = p.strip_dirs().sort_stats('cumulative')
        stats.print_stats()
        statsfile.close()
        sys.exit(0)
    sys.exit(main())
